package cn.zbzcode.hrm.web.controller;

import cn.zbzcode.hrm.dto.SendSMSDto;
import cn.zbzcode.hrm.service.IVerifyCodeService;
import cn.zbzcode.hrm.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;


    //获取图片验证码
    @GetMapping("/verifycode/imageCode/{imageKey}")
    public AjaxResult createImageCode(@PathVariable("imageKey")String imageKey){
        String base64ImageStr = verifyCodeService.creatImageCode(imageKey);
        return AjaxResult.me().setResultObj(base64ImageStr);
    }
    //获取手机验证码
    @PostMapping("/verifycode/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody SendSMSDto sendSMSDto){
        try{
            verifyCodeService.sendSmsCode(sendSMSDto);
            return AjaxResult.me();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }

}